package com.bh.ly.oa.adapter;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bh.ly.oa.R;

public class SupplierSaleListAdapter  extends BaseAdapter {
	public List<JSONObject> getArray() {
		return array;
	}

	public void setArray(List<JSONObject> array) {
		this.array = array; 
	}

	List<JSONObject> array = null;
	Context context = null;

	public SupplierSaleListAdapter(Context contex) {
		this.context = contex;
//		this.array = HttpClent.getSuppliersaleJsonData(((SupplierSaleDailyActiivity)contex).getparamMap());
	}

	@Override
	public int getCount() {
		return array.size();
	}

	@Override
	public Object getItem(int position) {
		return array.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		OrderItem orderItem = null;
		if (convertView == null) {
			orderItem = new OrderItem();
			convertView = LayoutInflater.from(context).inflate(R.layout.supplier_sale_item, null); 
		} else {
			orderItem = (OrderItem) convertView.getTag();
		}
		
		JSONObject jsonObject = (JSONObject) array.get(position);
		orderItem.jsonobject=jsonObject;
		initView(position,convertView,orderItem);
		try {
			orderItem.suppliername.setText(jsonObject.getString("suppliername"));
			orderItem.recorddate.setText(jsonObject.getString("recorddate").subSequence(0, 10));
			
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return convertView;
	}
	
    private void initView(int position,View convertView,OrderItem orderItem){
        
		orderItem.suppliername = (TextView) convertView.findViewById(R.id.suppliername); 
		orderItem.recorddate = (TextView) convertView.findViewById(R.id.recorddate); 
        convertView.setTag(orderItem);
    }
    
	class OrderItem {
		TextView suppliername;
		TextView recorddate;
		JSONObject jsonobject;
	}
}
